<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * 用户请求参数验证
 * Author: Albert3306
 * Date: 2020/6/12 0012
 * @package App\Http\Requests
 */
class UsersRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [];
        // 根据不同场景验证不同的字段
        if ($this->segment(2) == 'login') {
            $rules = [
                'username'  => 'required',
                'password'  => 'required',
//                'captcha'   => 'required|captcha',
            ];
        }

        return $rules;
    }

    /**
     * 错误信息
     * Author: Albert3306
     * Date: 2020/6/11 0011
     * @return array|int[]
     */
    public function messages()
    {
        return [
            'username.required' => 1000,
            'password.required' => 1001,
            'captcha.required'  => 1002,
            'captcha.captcha'   => 1003,
        ];
    }
}
